'''
### Adapted from collective.flowplayer event subscibers
'''

from Products.Archetypes.interfaces import IObjectInitializedEvent

from apkn.extensions import ADDRESS_BOOK_VIEW
from apkn.extensions import LOG



class AddressBookLayout(object):
    '''
    Set the default layout for new address book objects
    '''
    def __init__(self, object, event):
        self.object = object
        self.content = content = event.object

        if not self.check_layout():
            if IObjectInitializedEvent.providedBy(event):
                self.content.setLayout(ADDRESS_BOOK_VIEW)
                LOG.info("Setting layout for address book :: %s",
                self.content.id)
        else:
            LOG.info("Layout already set for address book :: %s",
                    self.content.id)

    def check_layout(self):
        return self.content.getLayout() == ADDRESS_BOOK_VIEW
